package com.yc.cloud.admin.controller;

import com.yc.cloud.admin.dto.request.AvatarsWakeupCreateParam;
import com.yc.cloud.admin.dto.request.AvatarsWakeupUpdateParam;
import com.yc.cloud.admin.service.AvatarsWakeupService;
import com.yc.cloud.admin.vo.AvatarsWakeupVo;
import com.yc.cloud.basic.api.CommonPage;
import com.yc.cloud.basic.api.ResponseResult;
import com.yc.cloud.basic.dto.BaseQueryParam;
import com.yc.cloud.entity.AvatarsWakeup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.val;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 数字人唤醒词
 *
 * @author Yancy
 * @date 2024-04-10
 */
@RestController
@RequestMapping("/avatars/wakeup")
@Api(value = "数字人唤醒词", tags = "数字人唤醒词接口")
public class AvatarsWakeupController {

    @Resource
    private AvatarsWakeupService avatarsWakeupService;


    @GetMapping
    @ApiOperation(value = "数字人唤醒词列表", notes = "支持分页查询,字段模糊匹配,排序等")
    public ResponseResult<CommonPage<AvatarsWakeupVo>> list(BaseQueryParam param) {
        val result = avatarsWakeupService.list(param);
        return ResponseResult.success(CommonPage.restPage(result));
    }


    @GetMapping("{id}")
    @ApiOperation(value = "数字人唤醒词详情", notes = "根据ID查询")
    public ResponseResult<AvatarsWakeup> get(@PathVariable @ApiParam(value = "ID", required = true) Long id) {
        val result = avatarsWakeupService.get(id);
        return ResponseResult.success(result);
    }


    @PostMapping
    @ApiOperation(value = "添加数字人唤醒词", notes = "添加")
    public ResponseResult<AvatarsWakeup> create(@Validated @RequestBody AvatarsWakeupCreateParam param) {
        val result = avatarsWakeupService.create(param);
        return result != null ? ResponseResult.success(result) : ResponseResult.failed();
    }


    @ApiOperation(value = "删除数字人唤醒词", notes = "通过ID删除")
    @DeleteMapping(value = "{id}")
    public ResponseResult<Boolean> delete(@PathVariable @ApiParam(value = "ID", required = true) Long id) {
        val result = avatarsWakeupService.delete(id);
        return result ? ResponseResult.success(true) : ResponseResult.failed();
    }


    @ApiOperation(value = "修改数字人唤醒词", notes = "通过ID修改")
    @PutMapping(value = "{id}")
    public ResponseResult<AvatarsWakeup> update(@PathVariable @ApiParam(value = "ID", required = true) Long id, @Validated @RequestBody AvatarsWakeupUpdateParam param) {
        val result = avatarsWakeupService.update(id, param);
        return result != null ? ResponseResult.success(result) : ResponseResult.failed();
    }
}
